const App = getApp();
const navigationBarHeight = (getApp().diygwstatusBarHeight + 44) + 'px'
Page({
    data: {
        swipers1: [],
        currentIndex1: 0,
        msgs1: [],
        msgs2: [],
        url: App.Config.basePath,
        cid: 0,
        date: App.Tools.getCurrentDate(),
        date2: App.Tools.getCurrentDate2(),
    },

    //弹出提示信息
    showModal(message) {
        App.WxService.showModal({
            title: '友情提示',
            content: message,
            showCancel: !1,
        });
    },
    onShareAppMessage: function () {
    },

    //页面加载
    onLoad(option) {
        if (option) {
            this.setData({
                globalOption: option
            })
        }
    },

    //页面显示
    onShow() {
        this.getSwipers1();

        this.getMsgs2();

    },

    //页面跳转
    navigateTo(e) {
        App.navigateTo(e.currentTarget.dataset.url, e.currentTarget.dataset);
    },
    getSwipers1() {
        //调用数据
        var datas = [
            {thumb_url: '/assets/images/pic1.jpg', title: `滑块新闻一`, url: App.renderUrl('', 'index')},
            {thumb_url: '/assets/images/pic2.jpg', title: `滑块新闻二`, url: App.renderUrl('', 'index')},
            {thumb_url: '/assets/images/pic3.jpg', title: `滑块新闻三`, url: App.renderUrl('', 'index')}
        ];
        this.setData({
            swipers1: datas
        });
    },

    getMsgs1() {


        if (this.data.date>this.data.date2) {
           this.showModal("开始日期不能大于结束日期")
        } else {
            //设置要传递的参数
            let param = {
                f: 1,
                d1:this.data.date,
                d2:this.data.date2,
                loadmsg: `正在加载中`
            };

            App.HttpService.getData(param, "/roomtype_List").then(data => { //执行服务器Servlet
                this.setData({
                    msgs1: data //把从服务器端得到的值赋值给数组
                });
            });
        }


    },

    getMsgs2() {
        //设置要传递的参数
        let param = {
            f: 1,
            mid: wx.getStorageSync("mid"),
            loadmsg: `正在加载中`
        };

        App.HttpService.getData(param, "/coupon_List").then(data => { //执行服务器Servlet
            this.setData({
                msgs2: data //把从服务器端得到的值赋值给数组
            });
        });
    },

    lingqu(e){
        var  that=this;
        var mid= wx.getStorageSync("mid");

        if (mid=="") {
            this.setData({
                modalName:"Modal"
            })
        } else {
            let param = {
                cid:e.currentTarget.dataset.id,
                mid: wx.getStorageSync("mid"),
                loadmsg: `正在加载中`
            };

            App.HttpService.getData(param, "/receives_Add").then(data => { //执行服务器Servlet

                if (data[0].jieguo=="1") {
                this.showModal("您已经领取过此优惠券了，不允许重复领取！");
                } else {
                    App.WxService.showToast({
                        title: "领取成功!",
                        icon: 'success',
                        duration: 1000,
                    });
                    setTimeout(function() {
                        that.getMsgs2();
                    }, 1500)
                }


            });
        }
    },


    bindDateChange: function(e) {



        this.setData({
            date: e.detail.value
        })
    },

    bindDateChange2: function(e) {



        this.setData({
            date2: e.detail.value
        })
    },

    yuding(e)
    {
        var  that=this;
        var mid= wx.getStorageSync("mid");

        if (mid=="") {
            this.setData({
                modalName:"Modal"
            })
        } else {
            wx.navigateTo({
                url:"/pages/buy/index?id="+e.currentTarget.dataset.id+"&d1="+this.data.date+"&d2="+this.data.date2+"&r="+e.currentTarget.dataset.rname+"&p="+e.currentTarget.dataset.price
            })
        }

    },

    login(e)
    {
        var that=this;
        wx.getUserProfile({
            desc:'获取用户相关信息',
            success: res => {
                App.globalData.userInfo = res.userInfo
                console.log(App.globalData.userInfo);

                //调用数据
                let param = {
                    mname:App.globalData.userInfo.nickName,
                    addr:App.globalData.userInfo.avatarUrl
                };

                //调用数据
                App.HttpService.getData(param,"/members_Add").then(data=>{

                    wx.setStorageSync("mid",data[0].jieguo);

                    App.WxService.showToast({
                        title: "登录成功!",
                        icon: 'success',
                        duration: 1500,
                    });
                    setTimeout(function() {

                    }, 1500)

                    that.getMsgs2();
                    this.setData({
                        mid:-1,
                        modalName: null
                    })
                });


            }
        })
    },


})